from dicRead import dicRead
if __name__ == '__main__':
    fname = 'assignmentParts/part5.dict'
    d = dicRead(fname)
    (m_by_n, basicIndices, nonbasicIndices, bVec, aMat, cVec ) = d
    print m_by_n, basicIndices, nonbasicIndices, bVec, cVec, aMat
    fo = open(fname + '.output', 'w')
    enteringIdx = 0
    enteringArrIdx = 0
    for i, x in enumerate(cVec):
        if i == 0:
            continue
        print i,x
        if x > 0:
            enteringIdx = x
            enteringArrIdx = i
            break
    print 'Entering x%d' % nonbasicIndices[enteringArrIdx-1], ' with %d' % (enteringArrIdx-1)
    fo.write('%d\n'%nonbasicIndices[enteringArrIdx-1])
    coeff = 0
    ii = 0
    unbounded = True
    for i, x in enumerate(bVec):
        print i, x, aMat[i][enteringArrIdx-1]        
        if (aMat[i][enteringArrIdx-1] < 0 and aMat[i][enteringArrIdx-1]/x < coeff):
            coeff = aMat[i][enteringArrIdx-1]/x
            ii = i
            unbounded = False
    if (not unbounded):
        print 'x%d leaves' % basicIndices[ii], ' with %d' % ii
        fo.write('%d\n'%basicIndices[ii])
        newTarget = -(bVec[ii]/(aMat[ii][enteringArrIdx-1])*cVec[enteringArrIdx])+cVec[0]
        print (newTarget)
        fo.write('%f\n'%newTarget)
    else:
        print 'Unbounded'
        fo.write('UNBOUNDED')
    fo.close()